package info.fqtech.lingdemoweb;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author: jack
 * @date: 2018/11/4 17:1746
 * @version: 0.1
 * @description: <文件的作用>
 * @modified: <修改说明>
 **/
public class FirstTest extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 获取浏览器中参数名称叫name的值
        String name = req.getParameter("name");
        System.out.println("客户端输入了name:" + name);
        //获取第二个参数，age的值
//        String age = req.getParameter("age");
//        System.out.println("age:" + age);

        // 调用本地方法
        String responseStr = sayHello(name);
        System.out.println(responseStr);

        // 获取回复输出对象
        resp.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
        PrintWriter printWriter = resp.getWriter();
        printWriter.write(responseStr);
        printWriter.flush();
    }

    /**
     * 返回hello字符串
     * @param name
     * @return
     */
    public String sayHello(String name) {
        return name + ", Hello";
    }

}
